// pages/shoppingCart/shoppingCart.js
const app = getApp();

Page({
  data: {
    num : 1,
    card:[],
    useCard:[]
  },
  to(e){
    console.log(e.currentTarget.dataset.listid);
    wx.navigateTo({
      url: '/pages/MyOrdertext/MyOrdertext?listid='+e.currentTarget.dataset.listid,
    })
      
  },
  onLoad: function (options) {
    wx.request({  
      url: 'https://www.woodymidnight.cn/BCUHelper/api/list/selectbyrunnerid',  
      method: 'POST',
      data : {
        runnerId : app.data.userInfo.userid
      },
      header: { 'content-type': 'application/x-www-form-urlencoded' }, 
      success: res => {
        var data = res.data.data ;
        console.log("优惠券数据" , data);

        for(let i = 0 ; i < data.length ; i++){
          data[i].listtime = this.toData(data[i].listtime)
        }

        this.setData({
          card: data.reverse(),
          useCard: data.reverse(),
        })
      }
    })
  },

  // 点击三个头部选择栏触发函数
   changeOne:function(e){
        this.setData({
          num : 1
        })
      },

  changeTwo:function(e){
    var card = this.data.card
    var useCard = []
    for(var i = 0 ; i < card.length ; i++){
      if(card[i].liststate == 3){
        useCard.push(card[i])
      }
    }
    this.setData({
      useCard : useCard,
      num : 2
    })
  },

  onShow:function(e){
    this.onLoad()
  },

  changeThree:function(e){
    var card = this.data.card
    var useCard = []
    for(var i = 0 ; i < card.length ; i++){
      if(card[i].liststate == 1 || card[i].liststate == 2){
        useCard.push(card[i])
      }
    }
    this.setData({
      useCard : useCard,
      num : 3
    })
  },

  toData : function(number){
    var n=number;
    var date = new Date(n);
    var Y = date.getFullYear() + '/';
    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '/';
    var D = date.getDate()<10 ? '0'+date.getDate() : date.getDate();
    return (Y+M+D)
  }
})